<template>
	<div class="app-container">
		<jk-operation-card ref="box1" class="margin-bottom-10">
			<div class="flex-between-center-wrap">
				<div class="flex-start-center-wrap"></div>
				<div class="flex-end-center-wrap">
					<jk-select v-model="searchParams.machineId" clearable placeholder="机台" :option-list="machineList" size="small" class="search-bar-item-size2 margin-5-0 item-gap"></jk-select>
					<jk-search-button @click="onSearchBtn"></jk-search-button>
				</div>
			</div>
		</jk-operation-card>

		<jk-card>
			<jk-table ref="jkTable" border :loading="tableLoading" :data="tableData" :height="tableHeight + 20">
				<vxe-column type="seq" title="序号" width="80" align="center"></vxe-column>
				<vxe-column
					v-for="(item, index) in tableColumnList"
					:key="index"
					:title="item.title"
					:align="item.align"
					:field="item.keyName"
					:sortable="item.sortable"
					:fixed="item.fixed ? item.fixed : ''"
					:min-width="item.minWidth"
					:width="item.width"
				>
					<template slot-scope="scope">
						<el-tag v-if="item.keyName === 'deviceRecordNumber'" type="primary">{{ scope.row.deviceRecordNumber }}</el-tag>
						<span v-else>{{ scope.row[item.keyName] }}</span>
					</template>
				</vxe-column>
				<vxe-column title="操作" align="center" fixed="right" :width="190">
					<template slot-scope="scope">
						<div class="flex-center">
							<div class="item-gap"><el-button size="mini" type="success" @click="onDsBtn(scope.row)">断纱分布</el-button></div>
							<div class=""><el-button size="mini" type="primary" @click="onDsBtn(scope.row)">断纱排列</el-button></div>
						</div>
					</template>
				</vxe-column>
			</jk-table>

			<!-- 分页组件 -->
			<footer ref="box2" class="flex-end-center margin-top-10">
				<jk-page
					:page-index="searchParams.pageNo"
					:page-sizes="searchParams.pageSizes"
					:page-size="searchParams.pageSize"
					:total="totalCount"
					@on-change="onPageChange"
				/>
			</footer>
		</jk-card>
		<detail-dialog
			:data-item="dataItem"
			:dialog-state="detailDialogState"
			@on-visible-change="onVisibleChangeOfDetailDialog"
		></detail-dialog>
	</div>
</template>

<script>
    import calHeight from '/src/mixins/cal-table-height';
    import { pageConfig } from '/src/utils/jk/jk-tool';
    import {
        krGetDoffDataPage
    } from '/src/api/production/xsReport';
    import getMenuColumn from '../../../mixins/getMenuColumn';
    import handlerCache from '../../../mixins/handler-cache';
    import detailDialog from './detail-dialog';

    export default {
        name: 'DoffReport',
        components: {
            detailDialog
        },
        mixins: [calHeight, getMenuColumn, handlerCache],
        data() {
            return {
                apiItem: {
                    'page': krGetDoffDataPage
                },
                detailDialogState: false,
                machineList: [
                    { id: 25, name: 25 },
                    { id: 26, name: 26 },
                    { id: 27, name: 27 },
                    { id: 28, name: 28 },
                    { id: 29, name: 29 },
                    { id: 30, name: 30 },
                    { id: 9, name: 9 }
                ],
                dataItem: {},
                tableLoading: true,
                tableData: [],
                totalCount: null,
                searchParams: {
                    pageNo: pageConfig.pageNo,
                    pageSize: pageConfig.pageSize,
                    machineId: '',
                    ifTest: process.env.VUE_APP_MODE === 'development'
                }
            };
        },
        mounted() {
            this.getDependentData();
        },
        methods: {
            onDsBtn(row) {
                this.dataItem = row;
                this.detailDialogState = true;
            },
            onVisibleChangeOfDetailDialog(e) {
                if (!e) {
                    this.dataItem = {};
                }
                this.detailDialogState = e;
            },
            onPageChange(e, size) {
                this.$set(this.searchParams, 'pageNo', e);
                this.$set(this.searchParams, 'pageSize', size);
                this.getListRequest();
            },
            clearCacheMethod() {
                // Object.assign(this.$data, this.$options.data());
                this.$nextTick(() => {
                    this.getDependentData();
                });
            },
            async getDependentData() {
                this.tableLoading = true;
                await this.getMenuColumnListRequest();
                await this.getListRequest();
                this.tableLoading = false;
            },
            /** 查询列表 */
            getListRequest() {
                this.tableLoading = true;
                return this.apiItem['page'](this.searchParams).then(res => {
                    this.tableLoading = false;
                    if (res.data.status === 200) {
                        this.tableData = res.data.res;
                        this.totalCount = res.data.count;
                    }
                });
            },
            /** 搜索按钮操作 */
            onSearchBtn() {
                this.searchParams.pageNo = 1;
                this.totalCount = 1;
                this.getListRequest();
            }
        }
    };
</script>
<style>
</style>
